package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.pojo.vo.CategoryListVO;
import cn.scxy.bookcity.service.ICategoryService;
import cn.scxy.bookcity.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    @GetMapping("/list/{id}")
    public JsonResult<List<CategoryListVO>> list(@PathVariable Long id){
        List<CategoryListVO> list = categoryService.list(id);
        return JsonResult.ok(list);
    }

    @PostMapping("/delete/{id}")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        categoryService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/enable")
    public JsonResult<Void> updateEnable(@PathVariable Long id) {
           categoryService.updateEnable(id);
           return JsonResult.ok();
    }

    @PostMapping("/{id}/disable")
    public JsonResult<Void> updateDisable(@PathVariable Long id) {
        categoryService.updateDisable(id);
        return JsonResult.ok();
    }

    @GetMapping("/list1/{id}")
    public JsonResult<List<CategoryListVO>> list1(@PathVariable Long id){
        List<CategoryListVO> categoryListVOS = categoryService.list1(id);
        return JsonResult.ok(categoryListVOS);
    }
}
